<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>state练习-点击修改元素背景颜色</title>
    <style>
        .container{
            width: 500px;
            height: 400px;
            background: #aef;
            margin: 50px auto;
        }
    </style>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.js"></script>

    <script type="text/babel">
        //类式组件
        class App extends React.Component{

            //状态
            state = {
                bg: '#aef'
            }

            //声明事件回调
            changeBg = () => {
                //获取元素
                // let container = document.querySelector(".container");
                // container.style.background = '#036';

                //修改状态 更新页面
                this.setState({
                    bg: '#036'
                });
            }

            render(){
                return <div className="container" onClick={this.changeBg} style={{background: this.state.bg}}>
                    </div>
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
</body>
</html>